package com;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 全排序算法
 * @author litianyi
 *
 * 2015年11月5日
 */
public class FullSort {

	private static int count = 0;
	
	private static String[] array = {"a","b","c","d"};
	
	public static void main(String[] args) {
		sort();
		System.out.println("count="+count);
	}
//	n(n-1)(n-2)...
	public static void sort(){
//		有m个位置 每个字符 挨个去坐位置
		
			List<String> newList = new ArrayList<String>();
			List<String> tempList = new ArrayList<String>(Arrays.asList(array));
			print(newList,tempList);
	}
	
	public static void print(List<String> newList,List<String> tempList){
		//=4才输出
//		if(newList.size()==array.length){
			for(String str :newList){
				System.out.print(str + ",");
			}
			System.out.println();
			count++;
//		}
		
		for(String t : tempList){
			List<String> newList1 = new ArrayList<String>(newList);
			List<String> tempList1 = new ArrayList<String>(tempList);
			newList1.add(t);
			tempList1.remove(t);
			print(newList1,tempList1);
			
		}
		
	}
		
	
	
	

}
